<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<style>
	.dashboard-info-left{
		position:relative;
	}
</style>
<?php 
	$ci = &get_instance();
	$USER = getAccountUserObject();
	$ESCORT = $ci->escort_entity->init('user_id',$USER->getId());
	$LOCKED = $ci->locked_escort_entity->init('escort_id', $ESCORT->getId());
	
	$weekdayArray = getScheduleInWeekData_ioc();
	$weekdaySelected = $ESCORT->getWeekdaysArray($ESCORT->getId());
	$workingPlacesArray = explode(',', $ESCORT->getWorkingPlaceIds());
	$travelsArray = explode(',', $ESCORT->getTravelIds());
	$servesArray = explode(',', $ESCORT->getServesToIds());
	$servicesArray = explode(',', $ESCORT->getServiceIds());
?>

<form action="<?php echo site_url('escorts/submit_data/submit_services');?>" name="submit_services" id="submit_services" method="post" enctype="multipart/form-data" >
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('services_schedule');?></span>
			<div class="help-text" title="<?php echo language_translate('services_schedule_hint');?>"></div>
		</div>
		<div class="dashboard-info-right" style="position:relative">
			<div class="select-box" style="margin-right:10px;">
				<?php foreach($weekdayArray as $key=>$value): ?>
					<?php 
						$checked = in_array($key,$weekdaySelected) ? 'checked="checked"':'';
						$SCHEDULE = $ESCORT->getSchedule($ESCORT->getId(), $key);
						$from = $SCHEDULE ? $SCHEDULE->from : ''; 
						$to = $SCHEDULE ? $SCHEDULE->to : '';
					?>
					<div class="checkbox-wrapper" style="float:left;width:110px;">
						<input type='checkbox' name='services_weekdays[]' value='<?php echo $key;?>' class="custom" <?php echo $checked;?> />
						<label><?php echo $value;?></label>
					</div>
					<div style="float:left;">	
						<label style="margin-right:5px;float:left;"><?php echo language_translate('services_from');?></label> <?php echo form_dropdown("services_time_from_$key", getHourAndMinuteOptionData_ioc(), array($from) , "id=\"services_time_from_$key\" class=\"custom\" " );?>
					</div> 
					<div style="float:left;margin-left:5px;">	
						<label style="margin-right:5px;float:left;"><?php echo language_translate('services_to');?></label> <?php echo form_dropdown("services_time_to_$key", getHourAndMinuteOptionData_ioc(), array($to) , "id=\"services_time_to_$key\" class=\"custom\" " );?>
					</div> 
					<div class="clear"></div>
				<?php endforeach;?>
			</div>
			<div class="input-box" style="margin-right:0px;">
				<input type="checkbox" onoff="1" value="1" name="services_public_schedule" class="custom" 
					<?php echo $ESCORT->getPublicSchedule() == 1 ? "checked='checked'":''; ?> />
			</div>
			<div class="clear"></div>
			<?php if($LOCKED->getLockedSchedule() == 1):?>
				<div class="locked" style="position:absolute;top:0px;right:-5px;"></div>
			<?php endif;?>	
			
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('services_calendar');?></span>
			<div class="help-text" title="<?php echo language_translate('services_calendar_hint');?>"></div>
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<?php 
					echo dayMonthYearSelectBox(0, 'servcies_day', 'services_month', 'sevices_year', array('y'), 'class="custom"' );
				?>
			</div>
			<div class="input-box" style="margin-right:0px;">
				<input type="checkbox" onoff="1" value="1" name="services_public_calendar" class="custom" 
					<?php echo $ESCORT->getPublicWorkingCalendar() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedWorkingCalendar() == 1):?>
				<div class="locked"></div>
			<?php endif;?>	
			
			<div class="clear"></div>
			<br />
			<div class="select-box">
				<?php echo language_translate('services_month');?><br/>
				<?php 
					echo dayMonthYearSelectBox(0, 'servcies_day', 'services_month', 'sevices_year', array('m'), 'class="custom"' );
				?>
			</div>
			<div class="select-box">
				<?php echo language_translate('services_select_days');?><br/>
				<div id="multi-checkbox-sl-days">
					<?php 
						$yearNow = date('Y',time());
						$monthNow = date('m',time());
						 
						$WORKING_OBJ = $ESCORT->getWorkingCalendar($ESCORT->getId(), intval($yearNow), intval($monthNow));
						$dateArray = $WORKING_OBJ ? explode(',',$WORKING_OBJ->dates) : array() ;
					?>
					<?php echo multi_checkbox($name_array = "days_in_month[]", $value_key_array= daysInMonthDataArray( 1, 2010 ), $value_checked=$dateArray, $divStyle='', $inputStyle ='', true);?>
				</div>
				<?php echo loader_image_s('id="loading-loading-image-days-in-month" class="hidden"');?>
			</div>
			
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('services_working_places');?></span>
			<div class="help-text" title="<?php echo language_translate('services_working_hint');?>"></div>
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<?php 
					echo multi_checkbox($name_array = "services_working_places[]", $value_key_array= getWorkingPlaceData_ioc(), $value_checked=$workingPlacesArray, $divStyle='', $inputStyle ='');
				?>
			</div>
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="services_public_working_places" class="custom" 
					<?php echo $ESCORT->getPublicWorkingPlaces() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedWorkingPlaces() == 1):?>
				<div class="locked"></div>
			<?php endif;?>	
			
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('services_travels');?></span>
			<div class="help-text" title="<?php echo language_translate('services_travels_hint');?>"></div>
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<?php 
					echo multi_checkbox($name_array = "services_travels[]", $value_key_array= getTravelPlaceData_ioc(), $value_checked=$travelsArray, $divStyle='', $inputStyle ='');
				?>
			</div>
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="services_public_travels" class="custom" 
					<?php echo $ESCORT->getPublicTravel() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedTravel() == 1):?>
				<div class="locked"></div>
			<?php endif;?>	
			
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('services_serves');?></span>
			<div class="help-text" title="<?php echo language_translate('services_serves_hint');?>"></div>
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<?php 
					echo multi_checkbox($name_array = "services_serves[]", $value_key_array= getServesToData_ioc(), $value_checked=$servesArray, $divStyle='', $inputStyle ='');
				?>
			</div>
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="services_public_serves" class="custom" 
					<?php echo $ESCORT->getPublicServesTo() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedServe_to() == 1):?>
				<div class="locked"></div>
			<?php endif;?>	
			
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('services_services');?></span>
			<div class="help-text" title="<?php echo language_translate('services_services_hint');?>"></div>
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
			<?php $i=0;$m=ceil(count(getServicesData_ioc())/2); foreach(getServicesData_ioc() as $key => $value): $i++;?>	
				<?php $checked = in_array($key, $servicesArray) ? 'checked="checked"':'';?>
					<div class="checkbox-wrapper">
						<input type="checkbox" <?php echo $checked;?> value="<?php echo $key?>" name="services_services[]" class="custom" /> <label><?php echo $value;?></label>
					</div>
				<?php if($i%$m == 0):?>
					</div>
					<div class="select-box">
				<?php endif;?>	
			<?php endforeach;?>	
			</div>
			<div class="input-box">
				<input type="checkbox" onoff="1" value="1" name="services_public_services" class="custom" 
					<?php echo $ESCORT->getPublicServices() == 1 ? "checked='checked'":''; ?> />
			</div>
			
			<?php if($LOCKED->getLockedServices() == 1):?>
				<div class="locked"></div>
			<?php endif;?>	
			
		</div>
		
		<div class="clear"></div>
	</div>
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"><span>&nbsp;</span></div>
		<div class="dashboard-info-right">
			<div class="link-box">
				<a href="javascript:void(0);" onclick="return open_question_dialog(<?php echo $ESCORT->getId();?>);"><?php echo language_translate('services_question');?></a>
			</div>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"> 
			<div class="select-box">
				<input type="submit" class="save-button" value="<?php echo language_translate('services_save');?>" /> 
			</div>
		 </div>
		 <div class="dashboard-info-right">
			<?php echo loader_image("id='services_loader_image' class='hidden'");?>
		</div>
		<div class="clear"></div>
	</div>	 
	
	<div class="dashboard-info-wrapper">
		<div id="update-message"><?php echo language_translate('update_successfully_message');?></div>
		<div class="clear"></div>
	</div>
	
</form>

<script type="text/javascript">
$(document).ready(function() { 
	var options = { 
		beforeSubmit:  validateB4SubmitServices,  
		success:       processAfterRespondingServices   
	};	
	$('#submit_services').ajaxForm(options); 
	$('#services_month, #sevices_year').live('change',function(){
		loadAsyncDaysInMonth();
	});
	$('input[name=days_in_month\\[\\]]').live('change',function(){
		saveCalendarsWorking();
	});
	$('.help-text[title]').qtip({ style: { name: 'dark', tip: true } });
});	
function loadAsyncDaysInMonth(){
	$year = $('#sevices_year').val();
	$month = $('#services_month').val();
	$('#loading-loading-image-days-in-month').show();
	$('#multi-checkbox-sl-days').html('');
	$.post(BASE_URI+'escorts/async/loadAsyncDaysInMonth',{year:$year,month:$month},function(res){
		$('#loading-loading-image-days-in-month').hide();
		$('#multi-checkbox-sl-days').html(res);
		$('#multi-checkbox-sl-days input:checkbox:not([onoff]).custom').checkbox({cls:'jquery-safari-checkbox'});
		$('#multi-checkbox-sl-days input[onoff]:checkbox.custom').checkbox();
	});
}
function saveCalendarsWorking(){
	$year = $('#sevices_year').val();
	$month = $('#services_month').val();
	$datesArray = getMultiCheckbox('days_in_month');
	$datesString = $datesArray ? $datesArray.join(','):'';
	$.post(BASE_URI+'escorts/async/saveCalendarWorking_async',{year:$year, month:$month, date:$datesString},function(res){
		if(res != 'ok')
			debug(res);
	});
}
function validateB4SubmitServices(formData, jqForm, options){
	$('#services_loader_image').show();
	return true;
}

function processAfterRespondingServices(responseText, statusText, xhr, $form) {
	$('#services_loader_image').hide();	
	if(responseText == 'ok'){
		updatedShow();
	}else{
		debug(responseText);
	}
}
</script>	